package response

import (
	"net/http"

	"github.com/gin-gonic/gin"
)

func Success(c *gin.Context, data interface{}) {
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "success",
		"data": data,
	})
}

func Error(c *gin.Context, code int, err error) {
	c.JSON(http.StatusOK, gin.H{
		"code": code,
		"msg":  err.Error(),
		"data": nil,
	})
}

func CreateJson(c *gin.Context, msg string, data interface{}) {
	c.JSON(http.StatusCreated, gin.H{
		"code": 200,
		"msg":  msg,
		"data": data,
	})
}

func Abort404(c *gin.Context, code int, err error) {
	c.JSON(http.StatusNotFound, gin.H{
		"code": code,
		"msg":  err.Error(),
		"data": nil,
	})
	c.Abort()
}

func Abort500(c *gin.Context, code int, err error) {
	c.JSON(http.StatusInternalServerError, gin.H{
		"code": code,
		"msg":  err.Error(),
		"data": nil,
	})
	c.Abort()
}

func Abort401(c *gin.Context, code int, err error) {
	c.JSON(http.StatusUnauthorized, gin.H{
		"code": code,
		"msg":  err.Error(),
		"data": nil,
	})
	c.Abort()
}
